<!--
 * @Description: 
 * @Author: chenjiaxin
 * @Date: 2022-03-19 11:09:04
 * @LastEditTime: 2022-03-19 20:19:39
 * @FilePath: \WebSkillExtend\eg13-for循环执行效率\index.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>for循环用时</title>
  </head>
  <body>
    <script>
      let number = 10000000;
      let arr = new Array(number).fill(1);

      let start = new Date().getTime();
      console.log("开始时间=", start, new Date());
      //1、for 6ms===最快
      // for (let index = 0; index < number; index++) {}

      //2、for-of   163ms===慢
      // let sum = 0;
      // for (const iterator of arr) {
      // }

      // 3、forEach   122ms====其次
      // arr.forEach((ele) => {});

      //4、for-in    2328ms====最慢
      // for (const key in arr) {
      // }

      //5、arr.map   147ms
      // arr.map((ele) => {});

      //6、arr.some   137ms
      arr.some((ele) => {});

      //
      let now = new Date().getTime();
      console.log("结束时间=", now, new Date());
      console.log(now - start);
    </script>
  </body>
</html>
